From 25997e94e859c39b21674ab1f8aae24274487ebb Mon Sep 17 00:00:00 2001
From: oliskoli
Date: Tue, 26 Aug 2008 22:05:57 +0000
Subject: [PATCH] Make waypoint geocache data dynamic. Only pointer for now,
not using format_specific_fs!
---
an1.c | 10 +++----
cet_util.c | 3 ++
cetus.c | 30 ++++++++++----------
csv_util.c | 65 ++++++++++++++++++++++---------------------
defs.h | 3 +-
duplicate.c | 4 +--
garmin.c | 18 ++++++------
gcdb.c | 12 ++++----
geo.c | 2 +-
geoniche.c | 14 +++++-----
gpx.c | 43 +++++++++++++++-------------
html.c | 28 +++++++++----------
kml.c | 26 ++++++++---------
lowranceusr.c | 2 +-
maggeo.c | 18 ++++++------
magproto.c | 6 ++--
mkshort.c | 2 +-
navicache.c | 19 +++++++------
palmdoc.c | 20 ++++++-------
quovadis.c | 4 +--
sort.c | 2 +-
text.c | 26 ++++++++---------
tomtom.c | 12 ++++----
util.c | 6 ++--
vcf.c | 8 +++---
waypt.c | 77 ++++++++++++++++++++++++++++++++++-----------------
26 files changed, 250 insertions(+), 210 deletions(-)
diff --git a/an1.c b/an1.c
index f7b85a570..a0460fd72 100644
--- a/an1.c
+++ b/an1.c
@@ -726,12 +726,12 @@ Write_One_AN1_Waypoint( const waypoint *wpt )
}
rec->name = xstrdup( wpt->description );
- if ( !nogc && wpt->gc_data.id ) {
- char *extra = xmalloc( 25 + strlen(wpt->gc_data.placer) + strlen( wpt->shortname ));
+ if ( !nogc && wpt->gc_data->id ) {
+ char *extra = xmalloc( 25 + strlen(wpt->gc_data->placer) + strlen( wpt->shortname ));
sprintf( extra, "\r\nBy %s\r\n%s (%1.1f/%1.1f)",
- wpt->gc_data.placer,
- wpt->shortname, wpt->gc_data.diff/10.0,
- wpt->gc_data.terr/10.0);
+ wpt->gc_data->placer,
+ wpt->shortname, wpt->gc_data->diff/10.0,
+ wpt->gc_data->terr/10.0);
rec->name = xstrappend( rec->name, extra );
xfree( extra );
}
diff --git a/cet_util.c b/cet_util.c
index f393b9112..4f754c550 100644
--- a/cet_util.c
+++ b/cet_util.c
@@ -996,6 +996,7 @@ cet_convert_waypt(const waypoint *wpt)
waypoint *w = (waypoint *)wpt;
format_specific_data *fs;
url_link *url_next;
+ geocache_data *gc_data = (geocache_data *)wpt->gc_data;
if ((cet_output == 0) && (w->wpt_flags.cet_converted != 0)) return;
@@ -1010,6 +1011,8 @@ cet_convert_waypt(const waypoint *wpt)
url_next->url = cet_convert_string(url_next->url);
url_next->url_link_text = cet_convert_string(url_next->url_link_text);
}
+ gc_data->placer = cet_convert_string(gc_data->placer);
+ gc_data->hint = cet_convert_string(gc_data->hint);
fs = wpt->fs;
while (fs != NULL)
diff --git a/cetus.c b/cetus.c
index 138625966..bb1597151 100644
--- a/cetus.c
+++ b/cetus.c
@@ -473,32 +473,32 @@ cetus_writewpt(const waypoint *wpt)
}
vdata += strlen( vdata ) + 1;
- if (wpt->gc_data.diff) {
+ if (wpt->gc_data->diff) {
xasprintf(&desc_geo, "%s%s by %s\n%.4s/%.4s %3.1f/%3.1f\n",
- wpt->gc_data.is_available==status_true ?
+ wpt->gc_data->is_available==status_true ?
"" : " (Disabled)",
- wpt->gc_data.is_archived==status_true ?
+ wpt->gc_data->is_archived==status_true ?
" (Archived)" : "",
- wpt->gc_data.placer,
- gs_get_cachetype(wpt->gc_data.type),
- gs_get_container(wpt->gc_data.container),
- wpt->gc_data.diff/10.0,
- wpt->gc_data.terr/10.0);
+ wpt->gc_data->placer,
+ gs_get_cachetype(wpt->gc_data->type),
+ gs_get_container(wpt->gc_data->container),
+ wpt->gc_data->diff/10.0,
+ wpt->gc_data->terr/10.0);
} else {
desc_geo = xstrdup("");
}
- if (wpt->gc_data.desc_short.utfstring) {
- char *stripped_html = strip_html(&wpt->gc_data.desc_short);
- desc_short = xstrdup(wpt->gc_data.diff == 0 ? "\n\n" : "");
+ if (wpt->gc_data->desc_short.utfstring) {
+ char *stripped_html = strip_html(&wpt->gc_data->desc_short);
+ desc_short = xstrdup(wpt->gc_data->diff == 0 ? "\n\n" : "");
desc_short = xstrappend(desc_short, xstrdup(stripped_html));
xfree(stripped_html);
} else {
desc_short = xstrdup("");
}
- if (wpt->gc_data.desc_long.utfstring) {
- char *stripped_html = strip_html(&wpt->gc_data.desc_long);
+ if (wpt->gc_data->desc_long.utfstring) {
+ char *stripped_html = strip_html(&wpt->gc_data->desc_long);
desc_long = xstrdup("\n\n");
desc_long = xstrappend(desc_long, xstrdup(stripped_html));
xfree(stripped_html);
@@ -531,8 +531,8 @@ cetus_writewpt(const waypoint *wpt)
}
vdata += strlen( vdata ) + 1;
- if (wpt->gc_data.hint) {
- char *hint = xstrdup(wpt->gc_data.hint);
+ if (wpt->gc_data->hint) {
+ char *hint = xstrdup(wpt->gc_data->hint);
rec->type = WptCache;
strncpy( vdata, hint, NOTESZ + 1 ) ;
xfree(hint);
diff --git a/csv_util.c b/csv_util.c
index e776f421b..6a83ed70d 100644
--- a/csv_util.c
+++ b/csv_util.c
@@ -926,6 +926,7 @@ static void
xcsv_parse_val(const char *s, waypoint *wpt, const field_map_t *fmp)
{
char *enclosure = "";
+ geocache_data *gc_data = NULL;
if (0 == strcmp(fmp->printfc, "\"%s\"")) {
enclosure = "\"";
@@ -1086,47 +1087,49 @@ xcsv_parse_val(const char *s, waypoint *wpt, const field_map_t *fmp)
case XT_ISO_TIME_MS:
wpt->creation_time = xml_parse_time(s, &wpt->microseconds);
break;
- case XT_GEOCACHE_LAST_FOUND:
- wpt->gc_data.last_found = yyyymmdd_to_time(s);
+ case XT_GEOCACHE_LAST_FOUND:
+ waypt_alloc_gc_data(wpt)->last_found = yyyymmdd_to_time(s);
break;
/* GEOCACHING STUFF ***************************************************/
case XT_GEOCACHE_DIFF:
/* Geocache Difficulty as an int */
- wpt->gc_data.diff = atof(s) * 10;
+ waypt_alloc_gc_data(wpt)->diff = atof(s) * 10;
break;
case XT_GEOCACHE_TERR:
/* Geocache Terrain as an int */
- wpt->gc_data.terr = atof(s) * 10;
+ waypt_alloc_gc_data(wpt)->terr = atof(s) * 10;
break;
case XT_GEOCACHE_TYPE:
/* Geocache Type */
- wpt->gc_data.type = gs_mktype(s);
+ waypt_alloc_gc_data(wpt)->type = gs_mktype(s);
break;
case XT_GEOCACHE_CONTAINER:
- wpt->gc_data.container = gs_mkcont(s);
+ waypt_alloc_gc_data(wpt)->container = gs_mkcont(s);
break;
case XT_GEOCACHE_HINT:
- wpt->gc_data.hint = csv_stringtrim(s, "", 0);
+ waypt_alloc_gc_data(wpt)->hint = csv_stringtrim(s, "", 0);
break;
case XT_GEOCACHE_PLACER:
- wpt->gc_data.placer = csv_stringtrim(s, "", 0);
+ waypt_alloc_gc_data(wpt)->placer = csv_stringtrim(s, "", 0);
break;
case XT_GEOCACHE_ISAVAILABLE:
+ gc_data = waypt_alloc_gc_data(wpt);
if ( case_ignore_strcmp(csv_stringtrim(s, "", 0), "False") == 0 )
- wpt->gc_data.is_available = status_false;
+ gc_data->is_available = status_false;
else if ( case_ignore_strcmp(csv_stringtrim(s, "", 0), "True") == 0 )
- wpt->gc_data.is_available = status_true;
+ gc_data->is_available = status_true;
else
- wpt->gc_data.is_available = status_unknown;
+ gc_data->is_available = status_unknown;
break;
case XT_GEOCACHE_ISARCHIVED:
+ gc_data = waypt_alloc_gc_data(wpt);
if ( case_ignore_strcmp(csv_stringtrim(s, "", 0), "False") == 0 )
- wpt->gc_data.is_archived = status_false;
+ gc_data->is_archived = status_false;
else if ( case_ignore_strcmp(csv_stringtrim(s, "", 0), "True") == 0 )
- wpt->gc_data.is_archived = status_true;
+ gc_data->is_archived = status_true;
else
- wpt->gc_data.is_archived = status_unknown;
+ gc_data->is_archived = status_unknown;
break;
/* GPS STUFF *******************************************************/
@@ -1700,50 +1703,50 @@ xcsv_waypt_pr(const waypoint *wpt)
wpt->microseconds, XML_LONG_TIME);
break;
case XT_GEOCACHE_LAST_FOUND:
- writebuff(buff, fmp->printfc, time_to_yyyymmdd(wpt->gc_data.last_found));
+ writebuff(buff, fmp->printfc, time_to_yyyymmdd(wpt->gc_data->last_found));
break;
/* GEOCACHE STUFF **************************************************/
case XT_GEOCACHE_DIFF:
/* Geocache Difficulty as a double */
- writebuff(buff, fmp->printfc, wpt->gc_data.diff / 10.0);
- field_is_unknown = !wpt->gc_data.diff;
+ writebuff(buff, fmp->printfc, wpt->gc_data->diff / 10.0);
+ field_is_unknown = !wpt->gc_data->diff;
break;
case XT_GEOCACHE_TERR:
/* Geocache Terrain as a double */
- writebuff(buff, fmp->printfc, wpt->gc_data.terr / 10.0);
- field_is_unknown = !wpt->gc_data.terr;
+ writebuff(buff, fmp->printfc, wpt->gc_data->terr / 10.0);
+ field_is_unknown = !wpt->gc_data->terr;
break;
case XT_GEOCACHE_CONTAINER:
/* Geocache Container */
- writebuff(buff, fmp->printfc, gs_get_container(wpt->gc_data.container));
- field_is_unknown = wpt->gc_data.container == gc_unknown;
+ writebuff(buff, fmp->printfc, gs_get_container(wpt->gc_data->container));
+ field_is_unknown = wpt->gc_data->container == gc_unknown;
break;
case XT_GEOCACHE_TYPE:
/* Geocache Type */
- writebuff(buff, fmp->printfc, gs_get_cachetype(wpt->gc_data.type));
- field_is_unknown = wpt->gc_data.type == gt_unknown;
+ writebuff(buff, fmp->printfc, gs_get_cachetype(wpt->gc_data->type));
+ field_is_unknown = wpt->gc_data->type == gt_unknown;
break;
case XT_GEOCACHE_HINT:
- writebuff(buff, fmp->printfc, NONULL(wpt->gc_data.hint));
- field_is_unknown = !wpt->gc_data.hint;
+ writebuff(buff, fmp->printfc, NONULL(wpt->gc_data->hint));
+ field_is_unknown = !wpt->gc_data->hint;
break;
case XT_GEOCACHE_PLACER:
- writebuff(buff, fmp->printfc, NONULL(wpt->gc_data.placer));
- field_is_unknown = !wpt->gc_data.placer;
+ writebuff(buff, fmp->printfc, NONULL(wpt->gc_data->placer));
+ field_is_unknown = !wpt->gc_data->placer;
break;
case XT_GEOCACHE_ISAVAILABLE:
- if ( wpt->gc_data.is_available == status_false )
+ if ( wpt->gc_data->is_available == status_false )
writebuff(buff, fmp->printfc, "False");
- else if ( wpt->gc_data.is_available == status_true )
+ else if ( wpt->gc_data->is_available == status_true )
writebuff(buff, fmp->printfc, "True");
else
writebuff(buff, fmp->printfc, "Unknown");
break;
case XT_GEOCACHE_ISARCHIVED:
- if ( wpt->gc_data.is_archived == status_false )
+ if ( wpt->gc_data->is_archived == status_false )
writebuff(buff, fmp->printfc, "False");
- else if ( wpt->gc_data.is_archived == status_true )
+ else if ( wpt->gc_data->is_archived == status_true )
writebuff(buff, fmp->printfc, "True");
else
writebuff(buff, fmp->printfc, "Unknown");
diff --git a/defs.h b/defs.h
index c4b28c2e6..a5ad29dac 100644
--- a/defs.h
+++ b/defs.h
@@ -442,7 +442,7 @@ typedef struct {
unsigned char heartrate; /* Beats/min. likely to get moved to fs. */
unsigned char cadence; /* revolutions per minute */
float temperature; /* Degrees celsius */
- geocache_data gc_data;
+ const geocache_data *gc_data;
format_specific_data *fs;
session_t *session; /* pointer to a session struct */
void *extra_data; /* Extra data added by, say, a filter. */
@@ -543,6 +543,7 @@ void xcsv_read_internal_style(const char *style_buf);
waypoint * find_waypt_by_name(const char *name);
void waypt_backup(signed int *count, queue **head_bak);
void waypt_restore(signed int count, queue *head_bak);
+geocache_data *waypt_alloc_gc_data(waypoint *wpt);
route_head *route_head_alloc(void);
void route_add (waypoint *);
diff --git a/duplicate.c b/duplicate.c
index f40e1bf5f..1043faf5d 100644
--- a/duplicate.c
+++ b/duplicate.c
@@ -141,9 +141,9 @@ compare(const void *a, const void *b)
const wpt_ptr *wa = (wpt_ptr *)a;
const wpt_ptr *wb = (wpt_ptr *)b;
- if ( wa->wpt->gc_data.exported < wb->wpt->gc_data.exported ) {
+ if ( wa->wpt->gc_data->exported < wb->wpt->gc_data->exported ) {
return 1;
- } else if ( wa->wpt->gc_data.exported > wb->wpt->gc_data.exported ) {
+ } else if ( wa->wpt->gc_data->exported > wb->wpt->gc_data->exported ) {
return -1;
}
diff --git a/garmin.c b/garmin.c
index db800c072..0bb920198 100644
--- a/garmin.c
+++ b/garmin.c
@@ -783,13 +783,13 @@ const char *
get_gc_info(waypoint *wpt)
{
if (global_opts.smart_names) {
- if (wpt->gc_data.type == gt_virtual) return "V ";
- if (wpt->gc_data.type == gt_unknown) return "? ";
- if (wpt->gc_data.type == gt_multi) return "Mlt ";
- if (wpt->gc_data.type == gt_earth) return "EC ";
- if (wpt->gc_data.type == gt_event) return "Ev ";
- if (wpt->gc_data.container == gc_micro) return "M ";
- if (wpt->gc_data.container == gc_small) return "S ";
+ if (wpt->gc_data->type == gt_virtual) return "V ";
+ if (wpt->gc_data->type == gt_unknown) return "? ";
+ if (wpt->gc_data->type == gt_multi) return "Mlt ";
+ if (wpt->gc_data->type == gt_earth) return "EC ";
+ if (wpt->gc_data->type == gt_event) return "Ev ";
+ if (wpt->gc_data->container == gc_micro) return "M ";
+ if (wpt->gc_data->container == gc_small) return "S ";
}
return "";
}
@@ -847,13 +847,13 @@ waypoint_write(void)
memcpy(way[i]->cmnt, wpt->description, strlen(wpt->description));
} else {
if (global_opts.smart_names &&
- wpt->gc_data.diff && wpt->gc_data.terr) {
+ wpt->gc_data->diff && wpt->gc_data->terr) {
#if 0
xasprintf(&src, "%s %s", &wpt->shortname[2], src);
#endif
snprintf(obuf, sizeof(obuf), "%s%d/%d %s",
get_gc_info(wpt),
- wpt->gc_data.diff, wpt->gc_data.terr,
+ wpt->gc_data->diff, wpt->gc_data->terr,
src);
memcpy(way[i]->cmnt, obuf, strlen(obuf));
} else {
diff --git a/gcdb.c b/gcdb.c
index 585f7c34b..a3c782b28 100644
--- a/gcdb.c
+++ b/gcdb.c
@@ -148,10 +148,10 @@ data_read(void)
wpt->notes = xstrappend(wpt->notes, recdata);
} else
if (!strncmp("diff", rec->dbfld[i].fldname,4)) {
- wpt->gc_data.diff = 10 * atof(recdata);
+ waypt_alloc_gc_data(wpt)->diff = 10 * atof(recdata);
} else
if (!strncmp("terr", rec->dbfld[i].fldname,4)) {
- wpt->gc_data.terr = 10 * atof(recdata);
+ waypt_alloc_gc_data(wpt)->terr = 10 * atof(recdata);
}
break;
#if 0
@@ -260,13 +260,13 @@ gcdb_write_wpt(const waypoint *wpt)
(int) wpt->longitude));
gcdb_add_to_rec(rec, "lon2", RECTYPE_TEXT, tbuf);
- if (wpt->gc_data.diff) {
- sprintf(tbuf, "%f", wpt->gc_data.diff / 10.0);
+ if (wpt->gc_data->diff) {
+ sprintf(tbuf, "%f", wpt->gc_data->diff / 10.0);
gcdb_add_to_rec(rec, "diff", RECTYPE_TEXT, tbuf);
}
- if (wpt->gc_data.terr) {
- sprintf(tbuf, "%f", wpt->gc_data.terr / 10.0);
+ if (wpt->gc_data->terr) {
+ sprintf(tbuf, "%f", wpt->gc_data->terr / 10.0);
gcdb_add_to_rec(rec, "terr", RECTYPE_TEXT, tbuf);
}
diff --git a/geo.c b/geo.c
index 47d3f26f3..55ea7955b 100644
--- a/geo.c
+++ b/geo.c
@@ -102,7 +102,7 @@ void wpt_name(const char *args, const char **unused)
wpt_tmp->description = xstrappend(wpt_tmp->description,args);
s = xstrrstr(wpt_tmp->description, " by ");
if (s) {
- wpt_tmp->gc_data.placer = xstrdup(s + 4);
+ waypt_alloc_gc_data(wpt_tmp)->placer = xstrdup(s + 4);
if (nuke_placer) {
*s = '\0';
diff --git a/geoniche.c b/geoniche.c
index 9b19b3313..a0992148b 100644
--- a/geoniche.c
+++ b/geoniche.c
@@ -589,7 +589,7 @@ wpt2icon(const waypoint *wpt)
else if (strstr(desc, "unk")) return 48;
else if (strstr(desc, "cam")) return 49;
- switch (wpt->gc_data.type) {
+ switch (wpt->gc_data->type) {
case gt_traditional: return 43;
case gt_multi: return 44;
case gt_locationless: return 45;
@@ -615,11 +615,11 @@ geoniche_geostuff(const waypoint *wpt)
char *gs = NULL, *tmp1, *tmp2, *tmp3;
char tbuf[10240];
- if (!wpt->gc_data.terr) {
+ if (!wpt->gc_data->terr) {
return NULL;
}
- snprintf(tbuf, sizeof(tbuf), "\n%s by %s\n\n", gs_get_cachetype(wpt->gc_data.type), wpt->gc_data.placer);
+ snprintf(tbuf, sizeof(tbuf), "\n%s by %s\n\n", gs_get_cachetype(wpt->gc_data->type), wpt->gc_data->placer);
gs = xstrappend(gs, tbuf);
/*
@@ -632,15 +632,15 @@ geoniche_geostuff(const waypoint *wpt)
/*
* 3 May 06: Added container type
*/
- snprintf(tbuf, sizeof(tbuf), "Container: %s\nDifficulty: %3.1f\nTerrain: %3.1f\n\n", gs_get_container(wpt->gc_data.container), wpt->gc_data.diff/10.0, wpt->gc_data.terr/10.0);
+ snprintf(tbuf, sizeof(tbuf), "Container: %s\nDifficulty: %3.1f\nTerrain: %3.1f\n\n", gs_get_container(wpt->gc_data->container), wpt->gc_data->diff/10.0, wpt->gc_data->terr/10.0);
gs = xstrappend(gs, tbuf);
- tmp1 = strip_html(&wpt->gc_data.desc_short);
- tmp2 = strip_html(&wpt->gc_data.desc_long);
+ tmp1 = strip_html(&wpt->gc_data->desc_short);
+ tmp2 = strip_html(&wpt->gc_data->desc_long);
gs = xstrappend(gs, tmp1);
gs = xstrappend(gs, tmp2);
- tmp3 = rot13(wpt->gc_data.hint);
+ tmp3 = rot13(wpt->gc_data->hint);
snprintf(tbuf, sizeof(tbuf), "\n\nHint: %s\n", tmp3);
gs = xstrappend(gs, tbuf);
diff --git a/gpx.c b/gpx.c
index b2fb3aa3d..e09319895 100644
--- a/gpx.c
+++ b/gpx.c
@@ -491,23 +491,24 @@ static void
tag_gs_cache(const char **attrv)
{
const char **avp;
+ geocache_data *gc_data = waypt_alloc_gc_data(wpt_tmp);
for (avp = &attrv[0]; *avp; avp+=2) {
if (strcmp(avp[0], "id") == 0) {
- wpt_tmp->gc_data.id = atoi(avp[1]);
+ gc_data->id = atoi(avp[1]);
} else if (strcmp(avp[0], "available") == 0) {
if (case_ignore_strcmp(avp[1], "True") == 0) {
- wpt_tmp->gc_data.is_available = status_true;
+ gc_data->is_available = status_true;
}
else if (case_ignore_strcmp(avp[1], "False") == 0) {
- wpt_tmp->gc_data.is_available = status_false;
+ gc_data->is_available = status_false;
}
} else if (strcmp(avp[0], "archived") == 0) {
if (case_ignore_strcmp(avp[1], "True") == 0) {
- wpt_tmp->gc_data.is_archived = status_true;
+ gc_data->is_archived = status_true;
}
else if (case_ignore_strcmp(avp[1], "False") == 0) {
- wpt_tmp->gc_data.is_archived = status_false;
+ gc_data->is_archived = status_false;
}
}
}
@@ -697,7 +698,7 @@ gpx_start(void *data, const XML_Char *xml_el, const XML_Char **xml_attr)
break;
case tt_cache_placer:
if (*attr && (0 == strcmp(attr[0], "id"))) {
- wpt_tmp->gc_data.placer_id = atoi(attr[1]);
+ waypt_alloc_gc_data(wpt_tmp)->placer_id = atoi(attr[1]);
}
default:
break;
@@ -933,41 +934,43 @@ gpx_end(void *data, const XML_Char *xml_el)
wpt_tmp->notes = xstrdup(cdatastrp);
break;
case tt_cache_container:
- wpt_tmp->gc_data.container = gs_mkcont(cdatastrp);
+ waypt_alloc_gc_data(wpt_tmp)->container = gs_mkcont(cdatastrp);
break;
case tt_cache_type:
- wpt_tmp->gc_data.type = gs_mktype(cdatastrp);
+ waypt_alloc_gc_data(wpt_tmp)->type = gs_mktype(cdatastrp);
break;
case tt_cache_difficulty:
sscanf(cdatastrp, "%f", &x);
- wpt_tmp->gc_data.diff = x * 10;
+ waypt_alloc_gc_data(wpt_tmp)->diff = x * 10;
break;
case tt_cache_hint:
rtrim(cdatastrp);
if (cdatastrp[0]) {
- wpt_tmp->gc_data.hint = xstrdup(cdatastrp);
+ waypt_alloc_gc_data(wpt_tmp)->hint = xstrdup(cdatastrp);
}
break;
case tt_cache_desc_long:
rtrim(cdatastrp);
if (cdatastrp[0]) {
- wpt_tmp->gc_data.desc_long.is_html = cache_descr_is_html;
- wpt_tmp->gc_data.desc_long.utfstring = xstrdup(cdatastrp);
+ geocache_data *gc_data = waypt_alloc_gc_data(wpt_tmp);
+ gc_data->desc_long.is_html = cache_descr_is_html;
+ gc_data->desc_long.utfstring = xstrdup(cdatastrp);
}
break;
case tt_cache_desc_short:
rtrim(cdatastrp);
if (cdatastrp[0]) {
- wpt_tmp->gc_data.desc_short.is_html = cache_descr_is_html;
- wpt_tmp->gc_data.desc_short.utfstring = xstrdup(cdatastrp);
+ geocache_data *gc_data = waypt_alloc_gc_data(wpt_tmp);
+ gc_data->desc_short.is_html = cache_descr_is_html;
+ gc_data->desc_short.utfstring = xstrdup(cdatastrp);
}
break;
case tt_cache_terrain:
sscanf(cdatastrp, "%f", &x);
- wpt_tmp->gc_data.terr = x * 10;
+ waypt_alloc_gc_data(wpt_tmp)->terr = x * 10;
break;
case tt_cache_placer:
- wpt_tmp->gc_data.placer = xstrdup(cdatastrp);
+ waypt_alloc_gc_data(wpt_tmp)->placer = xstrdup(cdatastrp);
break;
case tt_cache_log_date:
gc_log_date = xml_parse_time( cdatastrp, NULL );
@@ -979,8 +982,8 @@ gpx_end(void *data, const XML_Char *xml_el)
*/
case tt_cache_log_type:
if ((0 == strcmp(cdatastrp, "Found it")) &&
- (0 == wpt_tmp->gc_data.last_found)) {
- wpt_tmp->gc_data.last_found = gc_log_date;
+ (0 == wpt_tmp->gc_data->last_found)) {
+ waypt_alloc_gc_data(wpt_tmp)->last_found = gc_log_date;
}
gc_log_date = 0;
break;
@@ -1442,9 +1445,9 @@ fprint_xml_chain( xml_tag *tag, const waypoint *wpt )
if ( tag->child ) {
fprint_xml_chain(tag->child, wpt);
}
- if ( wpt && wpt->gc_data.exported &&
+ if ( wpt && wpt->gc_data->exported &&
strcmp(tag->tagname, "groundspeak:cache" ) == 0 ) {
- xml_write_time( ofd, wpt->gc_data.exported, 0,
+ xml_write_time( ofd, wpt->gc_data->exported, 0,
"groundspeak:exported" );
}
gbfprintf( ofd, "%s>\n", tag->tagname);
diff --git a/html.c b/html.c
index 3b2ac1329..ee1cc53be 100644
--- a/html.c
+++ b/html.c
@@ -104,41 +104,41 @@ html_disp(const waypoint *wpt)
else {
gbfprintf(file_out, "%s", wpt->description);
}
- if (wpt->gc_data.placer) {
- gbfprintf(file_out, " by %s", wpt->gc_data.placer);
+ if (wpt->gc_data->placer) {
+ gbfprintf(file_out, " by %s", wpt->gc_data->placer);
}
}
gbfprintf(file_out, "
\n");
gbfprintf (file_out, "");
- if (wpt->gc_data.terr) {
+ if (wpt->gc_data->terr) {
gbfprintf (file_out, " %d%s / %d%s \n",
- (int)(wpt->gc_data.diff / 10), (wpt->gc_data.diff%10)?"½":"",
- (int)(wpt->gc_data.terr / 10), (wpt->gc_data.terr%10)?"½":"" );
+ (int)(wpt->gc_data->diff / 10), (wpt->gc_data->diff%10)?"½":"",
+ (int)(wpt->gc_data->terr / 10), (wpt->gc_data->terr%10)?"½":"" );
gbfprintf(file_out, "%s / %s ",
- gs_get_cachetype(wpt->gc_data.type),
- gs_get_container(wpt->gc_data.container));
+ gs_get_cachetype(wpt->gc_data->type),
+ gs_get_container(wpt->gc_data->container));
}
gbfprintf(file_out, " | \n");
gbfprintf(file_out, "| ");
- if (wpt->gc_data.desc_short.utfstring) {
- char *tmpstr = strip_nastyhtml(wpt->gc_data.desc_short.utfstring);
+ if (wpt->gc_data->desc_short.utfstring) {
+ char *tmpstr = strip_nastyhtml(wpt->gc_data->desc_short.utfstring);
gbfprintf (file_out, " %s \n", tmpstr );
xfree( tmpstr );
}
- if (wpt->gc_data.desc_long.utfstring) {
- char *tmpstr = strip_nastyhtml(wpt->gc_data.desc_long.utfstring);
+ if (wpt->gc_data->desc_long.utfstring) {
+ char *tmpstr = strip_nastyhtml(wpt->gc_data->desc_long.utfstring);
gbfprintf (file_out, "%s \n", tmpstr );
xfree( tmpstr );
}
- if (wpt->gc_data.hint) {
+ if (wpt->gc_data->hint) {
char *hint = NULL;
if ( html_encrypt )
- hint = rot13( wpt->gc_data.hint );
+ hint = rot13( wpt->gc_data->hint );
else
- hint = xstrdup( wpt->gc_data.hint );
+ hint = xstrdup( wpt->gc_data->hint );
gbfprintf (file_out, "Hint: %s \n", hint);
xfree( hint );
}
diff --git a/kml.c b/kml.c
index 9c1f85805..28b210742 100644
--- a/kml.c
+++ b/kml.c
@@ -789,7 +789,7 @@ kml_lookup_gc_icon(const waypoint *waypointp)
/* This could be done so much better in C99 with designated
* initializers...
*/
- switch (waypointp->gc_data.type) {
+ switch (waypointp->gc_data->type) {
case gt_traditional: icon = "2.png"; break;
case gt_multi: icon = "3.png"; break;
case gt_virtual: icon = "4.png"; break;
@@ -815,7 +815,7 @@ kml_lookup_gc_container(const waypoint *waypointp)
{
const char *cont;
- switch (waypointp->gc_data.container) {
+ switch (waypointp->gc_data->container) {
case gc_micro: cont="micro"; break;
case gc_regular: cont="regular"; break;
case gc_large: cont="large"; break;
@@ -883,32 +883,32 @@ static void kml_geocache_pr(const waypoint *waypointp)
xfree(p);
}
- if (waypointp->gc_data.placer) {
- p = xml_entitize(waypointp->gc_data.placer);
+ if (waypointp->gc_data->placer) {
+ p = xml_entitize(waypointp->gc_data->placer);
kml_write_xml(0, "%s\n", p);
xfree(p);
}
- kml_write_xml(0, "%d\n", waypointp->gc_data.placer_id);
+ kml_write_xml(0, "%d\n", waypointp->gc_data->placer_id);
- kml_write_xml(0, "%s\n", kml_gc_mkstar(waypointp->gc_data.diff));
- kml_write_xml(0, "%s\n", kml_gc_mkstar(waypointp->gc_data.terr));
+ kml_write_xml(0, "%s\n", kml_gc_mkstar(waypointp->gc_data->diff));
+ kml_write_xml(0, "%s\n", kml_gc_mkstar(waypointp->gc_data->terr));
kml_write_xml(0, "%s\n", kml_lookup_gc_container(waypointp));
// Highlight any issues with the cache, such as temp unavail
// or archived.
kml_write_xml(0, "");
- if (waypointp->gc_data.is_archived == status_true) {
+ if (waypointp->gc_data->is_archived == status_true) {
kml_write_xml(0, "<font color=\"red\">This cache has been archived.</font> \n");
- } else if (waypointp->gc_data.is_available == status_false) {
+ } else if (waypointp->gc_data->is_available == status_false) {
kml_write_xml(0, "<font color=\"red\">This cache is temporarily unavailable.</font> \n");
}
kml_write_xml(0, "\n");
- kml_write_xml(0, "%s\n", gs_get_cachetype(waypointp->gc_data.type));
- kml_write_xml(0, "\n", waypointp->gc_data.desc_short.utfstring ? waypointp->gc_data.desc_short.utfstring : "");
- kml_write_xml(0, "\n", waypointp->gc_data.desc_long.utfstring ? waypointp->gc_data.desc_long.utfstring : "");
+ kml_write_xml(0, "%s\n", gs_get_cachetype(waypointp->gc_data->type));
+ kml_write_xml(0, "\n", waypointp->gc_data->desc_short.utfstring ? waypointp->gc_data->desc_short.utfstring : "");
+ kml_write_xml(0, "\n", waypointp->gc_data->desc_long.utfstring ? waypointp->gc_data->desc_long.utfstring : "");
kml_write_xml(-1, "\n");
@@ -942,7 +942,7 @@ static void kml_waypt_pr(const waypoint *waypointp)
}
#endif
- if (waypointp->gc_data.diff && waypointp->gc_data.terr) {
+ if (waypointp->gc_data->diff && waypointp->gc_data->terr) {
kml_geocache_pr(waypointp);
return;
}
diff --git a/lowranceusr.c b/lowranceusr.c
index 4620e8cf7..dd5ebbb96 100644
--- a/lowranceusr.c
+++ b/lowranceusr.c
@@ -732,7 +732,7 @@ lowranceusr_waypt_disp(const waypoint *wpt)
SymbolId = lowranceusr_find_icon_number_from_desc(wpt->icon_descr);
}
/* If the waypoint is archived or disabled, use a "disabled" icon instead. */
- if ( (wpt->gc_data.is_archived==status_true) || (wpt->gc_data.is_available==status_false) ) {
+ if ( (wpt->gc_data->is_archived==status_true) || (wpt->gc_data->is_available==status_false) ) {
SymbolId = lowranceusr_find_icon_number_from_desc("Disabled Cache");
}
diff --git a/maggeo.c b/maggeo.c
index 57e4fb5df..1bfd1f4a4 100644
--- a/maggeo.c
+++ b/maggeo.c
@@ -167,15 +167,15 @@ maggeo_waypt_pr(const waypoint *waypointp)
* For some reason, Magellan used exactly the GPX spellings of
* everything except this one...
*/
- if (waypointp->gc_data.type == gt_suprise) {
+ if (waypointp->gc_data->type == gt_suprise) {
ctype = "Mystery Cache";
} else {
- ctype = gs_get_cachetype(waypointp->gc_data.type);
+ ctype = gs_get_cachetype(waypointp->gc_data->type);
}
placeddate = maggeo_fmtdate(waypointp->creation_time);
- lfounddate = maggeo_fmtdate(waypointp->gc_data.last_found);
+ lfounddate = maggeo_fmtdate(waypointp->gc_data->last_found);
cname = mkshort(desc_handle, waypointp->notes ? waypointp->notes : waypointp->description);
- placer = waypointp->gc_data.placer;
+ placer = waypointp->gc_data->placer;
/*
* As of this writing on 05/04, the firmware in the units will
@@ -198,20 +198,20 @@ maggeo_waypt_pr(const waypoint *waypointp)
append(obuf, shortname);
append(obuf, cname);
append(obuf, placer);
- append(obuf, waypointp->gc_data.hint);
+ append(obuf, waypointp->gc_data->hint);
append(obuf, ctype);
append(obuf, placeddate);
append(obuf, lfounddate);
- if (waypointp->gc_data.diff/10.0)
+ if (waypointp->gc_data->diff/10.0)
sprintf(obuf + strlen(obuf), ",%3.1f",
- waypointp->gc_data.diff/10.0);
+ waypointp->gc_data->diff/10.0);
else
strcat(obuf, ",");
- if (waypointp->gc_data.terr/10.0)
+ if (waypointp->gc_data->terr/10.0)
sprintf(obuf + strlen(obuf), ",%3.1f",
- waypointp->gc_data.terr/10.0);
+ waypointp->gc_data->terr/10.0);
else
strcat(obuf, ",");
diff --git a/magproto.c b/magproto.c
index ae4187b0d..96aba229f 100644
--- a/magproto.c
+++ b/magproto.c
@@ -1291,9 +1291,9 @@ mag_waypt_pr(const waypoint *waypointp)
owpt = mag_cleanse(owpt);
if (global_opts.smart_icons &&
- waypointp->gc_data.diff && waypointp->gc_data.terr) {
- sprintf(ofmtdesc, "%d/%d %s", waypointp->gc_data.diff,
- waypointp->gc_data.terr, odesc);
+ waypointp->gc_data->diff && waypointp->gc_data->terr) {
+ sprintf(ofmtdesc, "%d/%d %s", waypointp->gc_data->diff,
+ waypointp->gc_data->terr, odesc);
odesc = mag_cleanse(ofmtdesc);
} else {
odesc = mag_cleanse(odesc);
diff --git a/mkshort.c b/mkshort.c
index 5e417724d..748fd5f9f 100644
--- a/mkshort.c
+++ b/mkshort.c
@@ -587,7 +587,7 @@ mkshort_from_wpt(short_handle h, const waypoint *wpt)
* which contains placer name, diff, terr, and generally way
* more stuff than should be in any one field...
*/
- if (wpt->gc_data.diff && wpt->gc_data.terr &&
+ if (wpt->gc_data->diff && wpt->gc_data->terr &&
wpt->notes && wpt->notes[0]) {
return mkshort(h, wpt->notes);
}
diff --git a/navicache.c b/navicache.c
index 3393a3323..5e416e798 100644
--- a/navicache.c
+++ b/navicache.c
@@ -116,7 +116,10 @@ nav_start(void *data, const XML_Char *xml_el, const XML_Char **xml_attr)
attr = xml_convert_attrs_to_char_string(xml_attr);
if (0 == strcmp(el, "CacheDetails")) {
const char **ap;
+ geocache_data *gc_data;
wpt_tmp = waypt_new();
+ gc_data = waypt_alloc_gc_data(wpt_tmp);
+
for (ap = attr; *ap; ap+=2) {
if (0 == strcmp(ap[0], "cache_id")) {
wpt_tmp->shortname = xstrdup(ap[1]);
@@ -139,17 +142,17 @@ nav_start(void *data, const XML_Char *xml_el, const XML_Char **xml_attr)
if (0 == strcmp(ap[0], "difficulty")) {
float x;
sscanf(ap[1], "%f", &x);
- wpt_tmp->gc_data.diff = x * 10;
+ gc_data->diff = x * 10;
} else
if (0 == strcmp(ap[0], "terrain")) {
float x;
sscanf(ap[1], "%f", &x);
- wpt_tmp->gc_data.terr = x * 10;
+ gc_data->terr = x * 10;
} else
if (0 == strcmp(ap[0], "cache_type")) {
static char buf[512];
- wpt_tmp->gc_data.type = nc_mktype(ap[1]);
+ gc_data->type = nc_mktype(ap[1]);
if (!strcmp(ap[1], "normal"))
wpt_tmp->icon_descr = "Geocache-regular";
else if (!strcmp(ap[1], "multi-part"))
@@ -183,15 +186,15 @@ nav_start(void *data, const XML_Char *xml_el, const XML_Char **xml_attr)
}
} else
if (0 == strcmp(ap[0], "cache_size")) {
- wpt_tmp->gc_data.container = nc_mkcont(ap[1]);
+ gc_data->container = nc_mkcont(ap[1]);
} else
if (0 == strcmp(ap[0], "description")) {
- wpt_tmp->gc_data.desc_long.is_html = 1;
- wpt_tmp->gc_data.desc_long.utfstring = xstrdup(ap[1]);
+ gc_data->desc_long.is_html = 1;
+ gc_data->desc_long.utfstring = xstrdup(ap[1]);
} else
if (0 == strcmp(ap[0], "comments")) {
- wpt_tmp->gc_data.desc_short.is_html = 1;
- wpt_tmp->gc_data.desc_short.utfstring = xstrdup(ap[1]);
+ gc_data->desc_short.is_html = 1;
+ gc_data->desc_short.utfstring = xstrdup(ap[1]);
}
}
waypt_add(wpt_tmp);
diff --git a/palmdoc.c b/palmdoc.c
index d6f0b55e6..e8c083a12 100644
--- a/palmdoc.c
+++ b/palmdoc.c
@@ -431,27 +431,27 @@ palmdoc_disp(const waypoint *wpt)
if (strcmp(wpt->description, wpt->shortname)) {
docprintf(10+strlen(wpt->description), "%s\n", wpt->description);
}
- if (wpt->gc_data.terr) {
+ if (wpt->gc_data->terr) {
- docprintf (100, "%s/%s\n", gs_get_cachetype(wpt->gc_data.type),
- gs_get_container(wpt->gc_data.container));
+ docprintf (100, "%s/%s\n", gs_get_cachetype(wpt->gc_data->type),
+ gs_get_container(wpt->gc_data->container));
- if (wpt->gc_data.desc_short.utfstring) {
- char *stripped_html = strip_html(&wpt->gc_data.desc_short);
+ if (wpt->gc_data->desc_short.utfstring) {
+ char *stripped_html = strip_html(&wpt->gc_data->desc_short);
docprintf (10+strlen(stripped_html), "\n%s\n", stripped_html);
xfree(stripped_html);
}
- if (wpt->gc_data.desc_long.utfstring) {
- char *stripped_html = strip_html(&wpt->gc_data.desc_long);
+ if (wpt->gc_data->desc_long.utfstring) {
+ char *stripped_html = strip_html(&wpt->gc_data->desc_long);
docprintf (10+strlen(stripped_html), "\n%s\n", stripped_html);
xfree(stripped_html);
}
- if (wpt->gc_data.hint) {
+ if (wpt->gc_data->hint) {
char *hint = NULL;
if ( palm_encrypt )
- hint = rot13( wpt->gc_data.hint );
+ hint = rot13( wpt->gc_data->hint );
else
- hint = xstrdup( wpt->gc_data.hint );
+ hint = xstrdup( wpt->gc_data->hint );
docprintf (10+strlen(hint), "\nHint: %s\n", hint);
xfree( hint );
}
diff --git a/quovadis.c b/quovadis.c
index 007dbb67f..295e272d2 100644
--- a/quovadis.c
+++ b/quovadis.c
@@ -131,7 +131,7 @@ data_read(void)
90.0 - (be_read32(&rec->latitude) / 1000000.0);
wpt_tmp->shortname = xstrdup(rec->name);
- wpt_tmp->gc_data.type =
+ waypt_alloc_gc_data(wpt_tmp)->type =
icon_to_wpt(be_read16(&rec->icon_bitmap));
waypt_add(wpt_tmp);
@@ -168,7 +168,7 @@ quovadis_writewpt(waypoint *wpt)
else {
rec->name[0] = '\0';
}
- be_write16(&rec->icon_bitmap, wpt_to_icon(wpt->gc_data.type));
+ be_write16(&rec->icon_bitmap, wpt_to_icon(wpt->gc_data->type));
be_write32(&rec->note_id, 0);
rec->name_scale = DEFAULT_NAME_SCALE;
rec->icon_scale = DEFAULT_ICON_SCALE;
diff --git a/sort.c b/sort.c
index 52c9bd810..cac8669e5 100644
--- a/sort.c
+++ b/sort.c
@@ -55,7 +55,7 @@ sort_comp(const queue * a, const queue * b)
const waypoint *x2 = (waypoint *)b;
switch (sort_mode) {
- case sm_gcid: return x1->gc_data.id - x2->gc_data.id;
+ case sm_gcid: return x1->gc_data->id - x2->gc_data->id;
case sm_shortname: return strcmp (x1->shortname, x2->shortname);
case sm_description: return strcmp (x1->description, x2->description);
case sm_time: return x1->creation_time - x2->creation_time;
diff --git a/text.c b/text.c
index ab04d7d1b..31bb486bc 100644
--- a/text.c
+++ b/text.c
@@ -130,30 +130,30 @@ text_disp(const waypoint *wpt)
if (strcmp(wpt->description, wpt->shortname)) {
gbfprintf(file_out, "%s", wpt->description);
- if (wpt->gc_data.placer)
- gbfprintf(file_out, " by %s", wpt->gc_data.placer);
+ if (wpt->gc_data->placer)
+ gbfprintf(file_out, " by %s", wpt->gc_data->placer);
}
- if (wpt->gc_data.terr) {
+ if (wpt->gc_data->terr) {
gbfprintf(file_out, " - %s / %s - (%d%s / %d%s)\n",
- gs_get_cachetype(wpt->gc_data.type), gs_get_container(wpt->gc_data.container),
- (int)(wpt->gc_data.diff / 10), (wpt->gc_data.diff%10)?".5":"",
- (int)(wpt->gc_data.terr / 10), (wpt->gc_data.terr%10)?".5":"" );
- if (wpt->gc_data.desc_short.utfstring) {
- char *stripped_html = strip_html(&wpt->gc_data.desc_short);
+ gs_get_cachetype(wpt->gc_data->type), gs_get_container(wpt->gc_data->container),
+ (int)(wpt->gc_data->diff / 10), (wpt->gc_data->diff%10)?".5":"",
+ (int)(wpt->gc_data->terr / 10), (wpt->gc_data->terr%10)?".5":"" );
+ if (wpt->gc_data->desc_short.utfstring) {
+ char *stripped_html = strip_html(&wpt->gc_data->desc_short);
gbfprintf (file_out, "\n%s\n", stripped_html);
xfree(stripped_html);
}
- if (wpt->gc_data.desc_long.utfstring) {
- char *stripped_html = strip_html(&wpt->gc_data.desc_long);
+ if (wpt->gc_data->desc_long.utfstring) {
+ char *stripped_html = strip_html(&wpt->gc_data->desc_long);
gbfprintf (file_out, "\n%s\n", stripped_html);
xfree(stripped_html);
}
- if (wpt->gc_data.hint) {
+ if (wpt->gc_data->hint) {
char *hint = NULL;
if ( txt_encrypt )
- hint = rot13( wpt->gc_data.hint );
+ hint = rot13( wpt->gc_data->hint );
else
- hint = xstrdup( wpt->gc_data.hint );
+ hint = xstrdup( wpt->gc_data->hint );
gbfprintf (file_out, "\nHint: %s\n", hint);
xfree( hint );
}
diff --git a/tomtom.c b/tomtom.c
index 6e23cf2c5..f9782810d 100644
--- a/tomtom.c
+++ b/tomtom.c
@@ -310,14 +310,14 @@ write_blocks( gbfile *f, struct blockheader *blocks ) {
char desc_field [256];
write_char( f, 2 );
if (global_opts.smart_names &&
- blocks->start[i].wpt->gc_data.diff &&
- blocks->start[i].wpt->gc_data.terr) {
+ blocks->start[i].wpt->gc_data->diff &&
+ blocks->start[i].wpt->gc_data->terr) {
snprintf(desc_field,sizeof(desc_field),"%s(t%ud%u)%s(type%dcont%d)",blocks->start[i].wpt->description,
- blocks->start[i].wpt->gc_data.terr/10,
- blocks->start[i].wpt->gc_data.diff/10,
+ blocks->start[i].wpt->gc_data->terr/10,
+ blocks->start[i].wpt->gc_data->diff/10,
blocks->start[i].wpt->shortname,
- (int) blocks->start[i].wpt->gc_data.type,
- (int) blocks->start[i].wpt->gc_data.container);
+ (int) blocks->start[i].wpt->gc_data->type,
+ (int) blocks->start[i].wpt->gc_data->container);
//Unfortunately enums mean we get numbers for cache type and container.
} else {
snprintf(desc_field, sizeof(desc_field), "%s",
diff --git a/util.c b/util.c
index 4fdd2bb7c..92fd7247f 100644
--- a/util.c
+++ b/util.c
@@ -920,7 +920,7 @@ get_cache_icon(const waypoint *waypointp)
* For icons, type overwrites container. So a multi-micro will
* get the icons for "multi".
*/
- switch (waypointp->gc_data.type) {
+ switch (waypointp->gc_data->type) {
case gt_virtual:
return "Virtual cache";
case gt_multi:
@@ -935,7 +935,7 @@ get_cache_icon(const waypoint *waypointp)
break;
}
- switch (waypointp->gc_data.container) {
+ switch (waypointp->gc_data->container) {
case gc_micro:
return "Micro-Cache";
break;
@@ -943,7 +943,7 @@ get_cache_icon(const waypoint *waypointp)
break;
}
- if (waypointp->gc_data.diff > 1) {
+ if (waypointp->gc_data->diff > 1) {
return "Geocache";
}
diff --git a/vcf.c b/vcf.c
index 0792af963..9067a976b 100644
--- a/vcf.c
+++ b/vcf.c
@@ -105,16 +105,16 @@ vcf_disp(const waypoint *wpt)
}
gbfprintf(file_out, "NOTE:");
- vcf_print_utf(&wpt->gc_data.desc_short);
+ vcf_print_utf(&wpt->gc_data->desc_short);
gbfprintf(file_out, "\\n");
- vcf_print_utf(&wpt->gc_data.desc_long);
+ vcf_print_utf(&wpt->gc_data->desc_long);
gbfprintf(file_out, "\\n\\nHINT:\\n");
if (vcf_encrypt) {
- char *s = rot13(wpt->gc_data.hint);
+ char *s = rot13(wpt->gc_data->hint);
vcf_print(s);
xfree(s);
} else {
- vcf_print(wpt->gc_data.hint);
+ vcf_print(wpt->gc_data->hint);
}
gbfprintf(file_out, "\nEND:VCARD\n");
diff --git a/waypt.c b/waypt.c
index 120b2ddea..3a03e461b 100644
--- a/waypt.c
+++ b/waypt.c
@@ -30,6 +30,7 @@ queue waypt_head;
static unsigned int waypt_ct;
static short_handle mkshort_handle;
int geocaches_present;
+static geocache_data empty_gc_data = {};
void
waypt_init(void)
@@ -68,20 +69,27 @@ waypt_dupe(const waypoint *wpt)
}
if (wpt->icon_descr && wpt->wpt_flags.icon_descr_is_dynamic)
tmp->icon_descr = xstrdup(wpt->icon_descr);
- if (wpt->gc_data.desc_short.utfstring) {
- tmp->gc_data.desc_short.utfstring =
- xstrdup(wpt->gc_data.desc_short.utfstring);
- }
- if (wpt->gc_data.desc_long.utfstring) {
- tmp->gc_data.desc_long.utfstring =
- xstrdup(wpt->gc_data.desc_long.utfstring);
+
+ if (wpt->gc_data != &empty_gc_data) {
+ geocache_data *gc_data = xmalloc(sizeof(*gc_data));
+ tmp->gc_data = (const geocache_data *)gc_data;
+
+ memcpy(gc_data, wpt->gc_data, sizeof(*gc_data));
+ if (wpt->gc_data->desc_short.utfstring) {
+ gc_data->desc_short.utfstring =
+ xstrdup(wpt->gc_data->desc_short.utfstring);
+ }
+ if (wpt->gc_data->desc_long.utfstring) {
+ gc_data->desc_long.utfstring =
+ xstrdup(wpt->gc_data->desc_long.utfstring);
+ }
+ if (wpt->gc_data->placer) {
+ gc_data->placer = xstrdup(wpt->gc_data->placer);
+ }
+ if (wpt->gc_data->hint) {
+ gc_data->hint = xstrdup(wpt->gc_data->hint);
+ }
}
- if (wpt->gc_data.placer) {
- tmp->gc_data.placer = xstrdup(wpt->gc_data.placer);
- }
- if (wpt->gc_data.hint) {
- tmp->gc_data.hint = xstrdup(wpt->gc_data.hint);
- }
/*
* It's important that this duplicated waypoint not appear
@@ -150,7 +158,7 @@ waypt_add(waypoint *wpt)
* all waypoints may have this and a few other pitfalls, but it's
* an easy and fast test here.
*/
- if (wpt->gc_data.diff && wpt->gc_data.terr) {
+ if (wpt->gc_data->diff && wpt->gc_data->terr) {
geocaches_present = 1;
}
}
@@ -175,6 +183,7 @@ waypt_new(void)
wpt->fix = fix_unknown;
wpt->sat = -1;
wpt->session = curr_session();
+ wpt->gc_data = &empty_gc_data;
QUEUE_INIT(&wpt->Q);
return wpt;
@@ -362,18 +371,24 @@ waypt_free( waypoint *wpt )
if (wpt->icon_descr && wpt->wpt_flags.icon_descr_is_dynamic) {
xfree((char *)(void *)wpt->icon_descr);
}
- if (wpt->gc_data.desc_short.utfstring) {
- xfree(wpt->gc_data.desc_short.utfstring);
- }
- if (wpt->gc_data.desc_long.utfstring) {
- xfree(wpt->gc_data.desc_long.utfstring);
- }
- if (wpt->gc_data.placer) {
- xfree(wpt->gc_data.placer);
+
+ if (wpt->gc_data != &empty_gc_data) {
+ geocache_data *gc_data = (geocache_data *)wpt->gc_data;
+
+ if (gc_data->desc_short.utfstring) {
+ xfree(gc_data->desc_short.utfstring);
+ }
+ if (gc_data->desc_long.utfstring) {
+ xfree(gc_data->desc_long.utfstring);
+ }
+ if (gc_data->placer) {
+ xfree(gc_data->placer);
+ }
+ if (gc_data->hint) {
+ xfree (gc_data->hint);
+ }
+ xfree(gc_data);
}
- if (wpt->gc_data.hint) {
- xfree (wpt->gc_data.hint);
- }
fs_chain_destroy( wpt->fs );
xfree(wpt);
}
@@ -585,3 +600,15 @@ waypt_course(const waypoint *A, const waypoint *B)
else
return 0;
}
+
+geocache_data *
+waypt_alloc_gc_data(waypoint *wpt)
+{
+ geocache_data *res = (geocache_data *)wpt->gc_data;
+ if (res == &empty_gc_data) {
+ res = xcalloc(1, sizeof(*res));
+ wpt->gc_data = (const geocache_data *)res;
+
+ }
+ return res;
+}
--
2.30.2
|